#pragma once

#include "../SuperGlob.hpp"
#include <set>

namespace BuildNG
{
  class TestDirectoryTree : public IDirectoryTree
  {
  public:
    TestDirectoryTree(const Glib::ustring &xml_file_name);

    virtual Glib::RefPtr<DirIt> get_dir_iterator(const Glib::ustring &path) const;
    virtual Glib::ustring get_root() const;
    virtual Glib::ustring get_cur_dir() const;

  private:

    class Dir : public Object
    {      
    public:
      Dir(const Xml::Element &xml,Dir *parent_dir);

      Dir* select_dir(const std::vector<Glib::ustring> &elements,int elem_index);
      Glib::ustring get_path() const;

      Dir *parent_dir;
      Glib::ustring name;

      std::map<Glib::ustring,Glib::RefPtr<Dir> > child_dirs;
      typedef std::map<Glib::ustring,Glib::RefPtr<Dir> >::iterator ChildDirsIt;
      std::set<Glib::ustring> files;
      typedef std::set<Glib::ustring>::iterator FilesIt;
    };
    Glib::RefPtr<Dir> root_dir;
    Glib::RefPtr<Dir> cur_dir;

    class DirItImpl : public DirIt
    {
    public:
      DirItImpl(Glib::RefPtr<Dir> dir);

      virtual bool move_next();
      virtual const Glib::ustring& get_cur();
      virtual bool is_directory();

    private:
      Glib::RefPtr<Dir> dir;
      Dir::ChildDirsIt dir_it;
      Dir::FilesIt files_it;

      enum State
      {
        State_UnInitiated,
        State_IteratingDirs,
        State_IteratingFiles,
        State_Ended,
      };
      State state;
    };
  };
}

